import sys

from PySide6.QtCore import Qt, QUrl
from PySide6.QtGui import QIcon, QDesktopServices
from PySide6.QtWidgets import QApplication, QFrame, QHBoxLayout
from qfluentwidgets import (NavigationItemPosition, MessageBox, setTheme, Theme, FluentWindow,
                            NavigationAvatarWidget, qrouter, SubtitleLabel, setFont, InfoBadge,
                            InfoBadgePosition, FluentBackgroundTheme)
from qfluentwidgets import FluentIcon as FIF

from app.databasemanager import DatabaseManager
from app.pet_show_window import PetShowWidget
from app.pet_add_window import PetAddWidget
from app.add_pet_battle_window import AddPetBattleWidget
from app.show_pet_battle_window import ShowPetBattleWidget
class Widget(QFrame):

    def __init__(self, text: str, parent=None):
        super().__init__(parent=parent)
        self.label = SubtitleLabel(text, self)
        self.hBoxLayout = QHBoxLayout(self)

        setFont(self.label, 24)
        self.label.setAlignment(Qt.AlignCenter)
        self.hBoxLayout.addWidget(self.label, 1, Qt.AlignCenter)
        self.setObjectName(text.replace(' ', '-'))

class MainWindow(FluentWindow):
    def __init__(self):
        super().__init__()
        setTheme(Theme.LIGHT)
        self.db = DatabaseManager("rock_pets.db")
        self.showpetInterface=PetShowWidget(self)
        self.addpetInterface=PetAddWidget(self)
        self.showpetbattleInterface=ShowPetBattleWidget(self)
        self.addpetbattleInterface=AddPetBattleWidget(self)

        self.initNavigation()
        self.initWindow()
        self.show()
    
    def initNavigation(self):
        # 添加主功能导航项
        self.addSubInterface(self.showpetInterface, FIF.VIEW, '展示宠物')
        self.addSubInterface(self.addpetInterface, FIF.ADD, '添加宠物')
        self.addSubInterface(self.showpetbattleInterface, FIF.GAME, '战斗对策')
        self.addSubInterface(self.addpetbattleInterface, FIF.CERTIFICATE, '添加对策')


    def initWindow(self):
        self.setMinimumSize(900, 950)
        self.setWindowTitle('洛克王国宠物大全（单机版）')
        
        # 居中窗口
        desktop = QApplication.primaryScreen().availableGeometry()
        w, h = desktop.width(), desktop.height()
        self.move(w//2 - self.width()//2, h//2 - self.height()//2)

    